Ensure dates are rounded to nearest second#66
Conversation
| # versions of netcdftime that didn't have microsecond precision. In those | ||
| # versions, a half-second value would be rounded up or down arbitrarily. It | ||
| # is probably not possible to replicate that behaviour with the current | ||
| # version (1.4.1), if one wished to do so for the sake of consistency. |
There was a problem hiding this comment.
Out of interest, why has this been provided as a multi-line comment rather than a docstring?
There was a problem hiding this comment.
This is just a comment for developers, so I don't think it should go in a docstring. I can provide a docstring based on L760-761 if you like, although this is a private function.
5924e09 to
9b813ba
Compare
9b813ba to
85a4f4f
Compare
|
Hmm... previously the |
Explicit is good 👍 |
|
Have you investigated whether you need to do the same for |
|
I support this in principal. I wonder whether we want to publicise this functionality and whether we want to enable access to microseconds @djkirkham do you feel that implementing such changes would be simply additive, from the changes posted here? |
|
@dkillick Good point. I hadn't looked into it, and it turns out that behaviour has changed. In the older version of netcdftime it seems |
Do you mean the functionality of being able to pass a list as argument?
It should be simple to add an optional argument to keep the microseconds |
We should indeed! And we should add a test that proves that the behaviour is correct, given that it's slipped through up to now. |
|
Actually I'm not sure about including microseconds, since they're not available in the older version of netcdftime. Should this be included as a note in the docstring? What should happen if the user requests microseconds when using the older version? Raise an exception? Ignore it and return seconds resolution? |
This is a good point. for now, I suggest we maintain the current behaviour, which explicitly ignores microseconds for all versions on netcdf4-python (this PR, as I understand it) Changes to include these, to provide options to functions and to provide public access to private functions are easy to add at a later date |
I agree. Banking this will be an excellent step forward and then we can take the time to think about the more complicated questions that @djkirkham raised. |
cf_units/__init__.py
Outdated
|
|
||
|
|
||
| def _num2date_to_nearest_second(time_value, utime): | ||
| # Return datetime encoding of numeric time value with respect to the given |
Ensures
num2datereturns datetimes rounded to one second. Allowing microsecond precision introduces rounding errors.